package com.asset.dispoal.channel.service.common;


import com.asset.dispoal.channel.domain.db.entity.SysChannelOpen;
import com.asset.dispoal.channel.domain.db.mapper.SysChannelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.math.BigDecimal;

/**
 * @author qr
 * @date 2022/3/25$
 */
@Component
public class SysChannelOpenDelCommand implements BaseCommand<String, Result> {

    @Autowired
    SysChannelMapper sysChannelMapper;

    @Override
    public Result execute(String id) {
        SysChannelOpen open = sysChannelMapper.getByOpenId(id);
        sysChannelMapper.openDelete(id);
        sysChannelMapper.payDeleteByOpenId(id);
        sysChannelMapper.addPayMoney(BigDecimal.ZERO.subtract(open.getMoney().subtract(open.getSurplus())),open.getChannelId());
        if("1".equals(open.getChecked())){
            sysChannelMapper.addOpenMoney(BigDecimal.ZERO.subtract(open.getMoney()),open.getChannelId());
        }
        return Result.ok();
    }
}
